package net.trustie.one;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import us.codecraft.webmagic.selector.Html;
import core.ModelPageProcessor;
import core.Pipeline;
import extension.RawPage;

/**
 * 抽取核心类
 * 主要执行
 */
public class Extractor {

	public List<RawPage> extract(List<RawPage> pages, Class<?> modelClass ) {
		
		ModelPageProcessor modelPageProcessor = new ModelPageProcessor();
		modelPageProcessor.addPageModel(modelClass);
		
		createPageList(pages);
		for (RawPage rawPage : pages) {
			if (rawPage.getPage() != null
					&& !rawPage.getPage().getResultItems().isSkip()) {
				modelPageProcessor.process(rawPage.getPage());
				rawPage.setExtracted(true);
			}
		}	
		return pages;
		
	}
	protected void createPageList(List<RawPage> rawPages) {
		for (RawPage rawPage : rawPages) {
			rawPage.generatPage();
		}
	}
	public RawPage extract(RawPage rawPage,Class<?> modelClass ) {
		ModelPageProcessor modelPageProcessor = new ModelPageProcessor();
		modelPageProcessor.addPageModel(modelClass);
		
		rawPage.generatPage();
		if (rawPage.getPage() != null
				&& !rawPage.getPage().getResultItems().isSkip()) {
			modelPageProcessor.process(rawPage.getPage());
			rawPage.setExtracted(true);
		}
		
		return rawPage;
	}

}

	
